<?php

Aero::load('db/base/result');

class MockDBResult extends AeroDatabaseResult
{
	function randomString ($numchar)
	{
		$string =str_shuffle("abcefghijklmnopqrstuvwxyz1234567890");
		$password = substr($string,1,$numchar);
		
		return($password);
	}
	
	function __construct ($sql)
	{
		$fields = array('id','foo','bar');
		$num = 100;
		$this->start = true;
		
		$this->result = array();
		
		for ($i=0; $i < $num; $i++)
		{
			$row = new stdclass();
			
			$row->id = $i;
			
			foreach ($fields as $column)
			{
				$row->$column = $this->randomString(rand(4,16));
			}
			
			array_push($this->result,$row);
		}
		
		$this->size = sizeof($this->result);
	}
	public function __destruct () 
	{
		return $this->result = array();
	}

	protected function _fetch ($container = 'object')
	{
		if ($this->start)
		{
			$row = current($this->result);
			$this->start = false;
		}
		else
			$row = next($this->result);
		
		if ($row === false)
			return false;
		
		switch ($container)
		{
			case 'object':
				return $row;
			case 'assoc':
				return get_object_vars($row);
			case 'array':
				return array_values(get_object_vars($row));
		}
	}

	protected function _seek ($offset) 
	{
		$this->start = true;
		reset($this->result);
		
		while ($offset-- > 0)
		{ 
			next($this->result);
			$this->start = false;
		}
		
		return true;
	}
}

